﻿using BLL;
using EncryptHelper;
using MODEL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.SessionState;

namespace Loginter.ajax
{
    /// <summary>
    /// TruckAdd 的摘要说明
    /// </summary>
    public class TruckAdd : IHttpHandler,IReadOnlySessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //车牌号码
            string trucknum = context.Request.Form["TruckNumber"];
            //车队名称
            string truckname = context.Request.Form["TruckName"];
            //车辆类型
            string type = context.Request.Form["Type"];
            //购买时间
            string buycat= context.Request.Form["BuyCat"];
            //车辆长度
            string length = context.Request.Form["Length"];
            //车辆吨位
            string dunwei =context.Request.Form["DunWei"];
            //备注
            string remark = context.Request.Form["Remark"];
            int sta = 1;
            //定义时间
            string time = DateTime.Now.ToShortDateString();
            TruckBLL truckbll = new TruckBLL();
            TruckTeamQueryModel tt = new TruckTeamQueryModel()
            {
                TeamName =truckname,
                Number = trucknum,
                BuyDate =Convert.ToDateTime(buycat),
                Type = type,
                Length = length,
                Tonngae=Convert.ToInt32(dunwei),
                State = sta,
                Remark = remark,
                CheckInTime = Convert.ToDateTime(time),
                AlterTime = Convert.ToDateTime(time)
            };
            int result = truckbll.UInsertTruck(tt);
            JavaScriptSerializer js = new JavaScriptSerializer();
            if (result == 1)
            {
                context.Session["TruckInfo"] = tt.TruckID;
                //context.Response.Write("yes");
                OperateResult usert = new OperateResult(1, "添加成功");
                string json = js.Serialize(usert);
                context.Response.Write(json);
            }
            else
            {
                OperateResult usert = new OperateResult(0, "添加失败");
                string json = js.Serialize(usert);
                context.Response.Write(json);
            }
    }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}